<template>
    <div class="rockwood-survey">
        <div class="header">
            <h1>{{ rockwoodConfig.title }}</h1>
            <p class="subtitle">{{ rockwoodConfig.subtitle }}</p>
            <div class="header-actions">
                <button @click="goToHome" class="home-btn">
                    <span class="home-icon">🏠</span> {{ rockwoodConfig.buttons.home }}
                </button>
                <button @click="showSettings = true" class="settings-btn">
                    <span class="settings-icon">⚙️</span> {{ rockwoodConfig.buttons.settings }}
                </button>
            </div>
        </div>

        <!-- 设置页面 -->
        <div class="settings-modal" v-if="showSettings">
            <div class="settings-content">
                <div class="settings-header">
                    <h2>{{ rockwoodConfig.settings.title }}</h2>
                    <button @click="closeSettings" class="close-btn">×</button>
                </div>

                <div class="settings-form">
                    <div class="form-group">
                        <label>问答编号：<span class="required">*</span></label>
                        <input type="text" v-model="recorderInfo.surveyId" placeholder="请输入问答编号（用于区分不同组的问卷）"
                            maxlength="20">
                        <p class="field-hint">编号用于区分不同组的问卷，建议使用如：ROCKWOOD001、CFS_A等格式</p>
                    </div>
                    <div class="form-group">
                        <label>记录人姓名：<span class="required">*</span></label>
                        <input type="text" v-model="recorderInfo.name" placeholder="请输入记录人姓名">
                    </div>
                    <div class="form-group">
                        <label>记录人职务/身份：<span class="required">*</span></label>
                        <input type="text" v-model="recorderInfo.position" placeholder="请输入职务或身份（如：医生、护士、研究员等）">
                    </div>
                    <div class="form-group">
                        <label>所属机构：</label>
                        <input type="text" v-model="recorderInfo.institution" placeholder="请输入所属医院或机构名称">
                    </div>
                    <div class="form-group">
                        <label>联系方式：</label>
                        <input type="text" v-model="recorderInfo.contact" placeholder="请输入联系电话或邮箱">
                    </div>
                    <div class="form-group">
                        <label>默认备注：</label>
                        <textarea v-model="recorderInfo.defaultRemarks" placeholder="请输入默认备注信息（可选）" rows="3"></textarea>
                    </div>
                </div>

                <div class="settings-actions">
                    <button @click="saveRecorderInfo" class="save-settings-btn">保存设置</button>
                    <button @click="closeSettings" class="cancel-btn">取消</button>
                </div>
            </div>
        </div>

        <!-- 记录人信息显示 -->
        <div class="recorder-info-display" v-if="recorderInfo.name && !showSettings && !showResult && !showExport">
            <div class="recorder-card">
                <div class="recorder-main-info">
                    <h3>问答编号：{{ recorderInfo.surveyId }}</h3>
                    <p>记录人：{{ recorderInfo.name }} | {{ recorderInfo.position }}</p>
                    <p v-if="recorderInfo.institution">{{ recorderInfo.institution }}</p>
                </div>
                <div class="recorder-actions">
                    <button @click="showSettings = true" class="edit-recorder-btn">编辑</button>
                    <button @click="showExportDialog" class="export-btn">{{ rockwoodConfig.buttons.export }}</button>
                </div>
            </div>
        </div>

        <!-- 导出数据模态框 -->
        <div class="export-modal" v-if="showExport">
            <div class="export-content">
                <div class="export-header">
                    <h2>{{ rockwoodConfig.export.title }}</h2>
                    <button @click="closeExport" class="close-btn">×</button>
                </div>

                <div class="export-form">
                    <div class="export-info">
                        <p><strong>当前问答编号：</strong>{{ recorderInfo.surveyId }}</p>
                        <p><strong>导出说明：</strong>将从服务器打包当前编号的所有Rockwood CFS评估数据</p>
                    </div>

                    <div class="form-group">
                        <label>导出密码：<span class="required">*</span></label>
                        <input type="password" v-model="exportPassword" placeholder="请输入导出密码" @keyup.enter="exportData">
                        <p class="field-hint">{{ rockwoodConfig.messages.passwordHint }}</p>
                    </div>

                    <div class="export-options">
                        <div class="form-group">
                            <label>
                                <input type="checkbox" v-model="exportOptions.includeRawData">
                                包含原始评估数据
                            </label>
                        </div>
                        <div class="form-group">
                            <label>
                                <input type="checkbox" v-model="exportOptions.includeStatistics">
                                包含统计分析
                            </label>
                        </div>
                    </div>
                </div>

                <div class="export-actions">
                    <button @click="exportData" class="export-confirm-btn" :disabled="!exportPassword">
                        <span v-if="!isExporting">导出压缩包</span>
                        <span v-else>导出中...</span>
                    </button>
                    <button @click="closeExport" class="cancel-btn">取消</button>
                </div>
            </div>
        </div>

        <div class="survey-form" v-if="!showResult && !showSettings && !showExport">
            <!-- 被评估人基本信息 -->
            <div class="section">
                <h2>{{ rockwoodConfig.sections.basicInfo.title }}</h2>
                <div class="form-group" v-for="field in rockwoodConfig.sections.basicInfo.fields" :key="field.name">
                    <label>{{ field.label }}：</label>
                    <input
                        v-if="field.type === 'text' || field.type === 'number' || field.type === 'tel' || field.type === 'datetime-local'"
                        :type="field.type" v-model="formData[field.name]" :placeholder="field.placeholder"
                        :min="field.min" :max="field.max" :step="field.step" :rows="field.rows">
                    <textarea v-else-if="field.type === 'textarea'" v-model="formData[field.name]"
                        :placeholder="field.placeholder" :rows="field.rows"></textarea>
                    <div v-else-if="field.type === 'radio'" class="radio-group">
                        <label v-for="option in field.options" :key="option.value">
                            <input type="radio" v-model="formData[field.name]" :value="option.value"> {{ option.label }}
                        </label>
                    </div>
                </div>
            </div>

            <!-- Rockwood CFS评估 -->
            <div class="section">
                <h2>{{ rockwoodConfig.sections.assessment.title }}</h2>
                <p class="assessment-description">{{ rockwoodConfig.sections.assessment.description }}</p>

                <div class="question-item" v-for="question in rockwoodConfig.sections.assessment.questions"
                    :key="question.id">
                    <h3>{{ question.title }}</h3>
                    <p class="question-desc">{{ question.description }}</p>

                    <!-- CFS评分选择 -->
                    <div v-if="question.type === 'radio' && question.id === 'cfsScore'" class="cfs-options">
                        <div v-for="option in question.options" :key="option.value" class="cfs-option">
                            <label class="cfs-label">
                                <input type="radio" v-model="formData[question.field]" :value="option.value">
                                <div class="cfs-content">
                                    <div class="cfs-header">
                                        <span class="cfs-score">{{ option.value }}分</span>
                                        <span class="cfs-level">{{ option.label.split(' - ')[1] }}</span>
                                    </div>
                                    <p class="cfs-description">{{ option.description }}</p>
                                </div>
                            </label>
                        </div>
                    </div>

                    <!-- 其他单选题 -->
                    <div v-else-if="question.type === 'radio'" class="radio-group">
                        <label v-for="option in question.options" :key="option.value">
                            <input type="radio" v-model="formData[question.field]" :value="option.value"> {{
                            option.label }}
                        </label>
                    </div>

                    <!-- 提示信息 -->
                    <p v-if="question.hint" class="hint">{{ question.hint }}</p>
                </div>
            </div>

            <div class="submit-section">
                <button @click="calculateResult" class="submit-btn" :disabled="!isFormValid">{{
                    rockwoodConfig.buttons.submit }}</button>
            </div>
        </div>

        <!-- 结果展示 -->
        <div class="result-section" v-if="showResult">
            <h2>{{ rockwoodConfig.result.title }}</h2>
            <div class="result-card">
                <div class="result-summary" :style="{ borderLeftColor: result.color }">
                    <h3>{{ result.level }}</h3>
                    <p class="score">{{ rockwoodConfig.result.score }}：{{ result.score }}/9</p>
                    <p class="category">{{ rockwoodConfig.result.category }}：{{ result.category }}</p>
                </div>

                <div class="result-details">
                    <h4>{{ rockwoodConfig.result.description }}：</h4>
                    <p class="level-description">{{ result.description }}</p>
                </div>

                <div class="result-supplements">
                    <h4>补充评估结果：</h4>
                    <ul>
                        <li>功能状态：{{ result.functionalStatus }}</li>
                        <li>活动能力：{{ result.mobilityLevel }}</li>
                    </ul>
                </div>

                <div class="result-recommendations">
                    <h4>{{ rockwoodConfig.result.recommendations }}：</h4>
                    <ul>
                        <li v-for="(rec, index) in result.recommendations" :key="index">{{ rec }}</li>
                    </ul>
                </div>

                <div class="result-explanation">
                    <h4>{{ rockwoodConfig.result.explanation.title }}：</h4>
                    <p v-for="item in rockwoodConfig.result.explanation.items" :key="item">{{ item }}</p>
                </div>

                <div class="action-buttons">
                    <button @click="saveToBackendOnly" class="save-btn" :disabled="isSaving">
                        <span v-if="!isSaving">{{ rockwoodConfig.buttons.save }}</span>
                        <span v-else>{{ rockwoodConfig.buttons.saving }}</span>
                    </button>
                    <button @click="resetForm" class="reset-btn">{{ rockwoodConfig.buttons.reset }}</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { rockwoodConfig } from '@/config/rockwoodConfig.js';
import { calculateRockwoodAssessment, calculateRockwoodStatistics, rockwoodLogic } from '@/config/rockwoodLogic.js';

export default {
    name: 'RockwoodSurvey',
    mounted() {
        // 自动设置当前时间
        const now = new Date();
        const year = now.getFullYear();
        const month = String(now.getMonth() + 1).padStart(2, '0');
        const day = String(now.getDate()).padStart(2, '0');
        const hours = String(now.getHours()).padStart(2, '0');
        const minutes = String(now.getMinutes()).padStart(2, '0');
        this.formData.recordTime = `${year}-${month}-${day}T${hours}:${minutes}`;

        // 加载记录人信息
        this.loadRecorderInfo();
    },
    data() {
        return {
            rockwoodConfig,
            showResult: false,
            showSettings: false,
            showExport: false,
            isExporting: false,
            isSaving: false,
            exportPassword: '',
            // 记录人信息（设置）
            recorderInfo: {
                surveyId: '',
                name: '',
                position: '',
                institution: '',
                contact: '',
                defaultRemarks: ''
            },
            // 导出选项
            exportOptions: rockwoodConfig.exportOptions,
            // 问卷表单数据
            formData: {
                // 被评估人信息
                patientName: '',
                age: null,
                gender: '',
                height: null,
                weight: null,
                phone: '',
                // 当前评估的记录时间和备注
                recordTime: '',
                remarks: '',
                // Rockwood CFS评估项目
                cfsScore: null,
                functionalAssessment: '',
                mobilityLevel: ''
            },
            result: {
                score: 0,
                level: '',
                category: '',
                description: '',
                color: '',
                recommendations: [],
                functionalStatus: '',
                mobilityLevel: ''
            }
        }
    },
    computed: {
        isFormValid() {
            // 个人信息字段已改为选填，不再进行必填验证
            return this.recorderInfo.surveyId &&
                this.recorderInfo.name &&
                this.recorderInfo.position &&
                this.formData.cfsScore !== null &&
                this.formData.functionalAssessment &&
                this.formData.mobilityLevel;
        },
        bmi() {
            if (this.formData.height && this.formData.weight) {
                return this.formData.weight / Math.pow(this.formData.height / 100, 2);
            }
            return 0;
        }
    },
    methods: {
        // 导航方法
        goToHome() {
            this.$router.push('/');
        },

        // 设置相关方法
        saveRecorderInfo() {
            // 验证必填字段
            if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
                alert(rockwoodConfig.messages.requiredFieldsError);
                return;
            }

            // 保存记录人信息到本地存储
            localStorage.setItem('rockwoodRecorderInfo', JSON.stringify(this.recorderInfo));
            // 设置默认备注
            if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
                this.formData.remarks = this.recorderInfo.defaultRemarks;
            }
            this.showSettings = false;
            alert(rockwoodConfig.messages.saveSuccess);
        },

        closeSettings() {
            this.showSettings = false;
        },

        loadRecorderInfo() {
            // 从本地存储加载记录人信息
            const saved = localStorage.getItem('rockwoodRecorderInfo');
            if (saved) {
                this.recorderInfo = JSON.parse(saved);
                // 设置默认备注
                if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
                    this.formData.remarks = this.recorderInfo.defaultRemarks;
                }
            }
        },

        // 导出相关方法
        showExportDialog() {
            this.showExport = true;
            this.exportPassword = '';
        },

        closeExport() {
            this.showExport = false;
            this.exportPassword = '';
            this.isExporting = false;
        },

        getSurveysByGroup(surveyId) {
            // 从本地存储获取指定编号的所有Rockwood CFS问卷
            const allSurveys = JSON.parse(localStorage.getItem('rockwoodSurveyData') || '[]');
            return allSurveys.filter(survey => survey.surveyId === surveyId);
        },

        async exportData() {
            this.isExporting = true;

            try {
                // 检查问答编号是否已设置
                if (!this.recorderInfo.surveyId || this.recorderInfo.surveyId.trim() === '') {
                    alert('请先设置问答编号！');
                    this.isExporting = false;
                    return;
                }

                // 发送导出请求到服务器
                const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/export-rockwood-survey`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        surveyId: this.recorderInfo.surveyId,
                        password: this.exportPassword,
                        exportOptions: this.exportOptions
                    })
                });

                if (response.status === 401) {
                    alert(rockwoodConfig.messages.passwordError);
                    return;
                }

                if (!response.ok) {
                    throw new Error('导出请求失败');
                }

                // 获取服务器返回的压缩包
                const blob = await response.blob();

                if (blob.size === 0) {
                    alert(rockwoodConfig.messages.noDataError);
                    return;
                }

                // 下载服务器生成的压缩包
                const url = window.URL.createObjectURL(blob);
                const link = document.createElement('a');
                link.href = url;
                link.download = `Rockwood_CFS数据_${this.recorderInfo.surveyId}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.zip`;
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
                window.URL.revokeObjectURL(url);

                alert(rockwoodConfig.messages.exportSuccess);
                this.closeExport();
            } catch (error) {
                console.error('导出失败:', error);
                alert(rockwoodConfig.messages.exportError);
            } finally {
                this.isExporting = false;
            }
        },

        generateExportContent(surveys) {
            const statistics = this.calculateStatistics(surveys);
            const summaryContent = rockwoodLogic.generateSummaryReport(surveys, statistics, this.recorderInfo);

            // 生成详细数据
            const detailContent = rockwoodLogic.generateDetailedCSV(surveys);

            return {
                summary: summaryContent,
                details: detailContent,
                surveys: surveys
            };
        },

        calculateStatistics(surveys) {
            return calculateRockwoodStatistics(surveys);
        },

        formatTime(timeString) {
            if (!timeString) return '未知时间';
            try {
                const date = new Date(timeString);
                return date.toLocaleString('zh-CN');
            } catch (error) {
                return timeString;
            }
        },

        generateIndividualReport(survey) {
            return rockwoodLogic.generateIndividualReport(survey, this.recorderInfo);
        },

        calculateResult() {
            // 使用Rockwood CFS评估逻辑
            this.result = calculateRockwoodAssessment(this.formData);
            this.showResult = true;
        },

        async saveToBackendOnly() {
            this.isSaving = true;

            try {
                // 1. 保存问卷数据到后台
                await this.saveToBackend();

                // 2. 生成评估报告内容
                const timestamp = new Date().toLocaleString('zh-CN');

                const content = rockwoodLogic.reportTemplates.assessmentReport(
                    this.formData,
                    this.recorderInfo,
                    this.result,
                    this.bmi
                );

                // 3. 保存评估报告到@data/文件夹
                await this.saveFileToDataFolder(content);

                // 4. 保存评估报告到本地存储（作为备份）
                const reportData = {
                    surveyId: this.recorderInfo.surveyId,
                    patientName: this.formData.patientName,
                    timestamp: timestamp,
                    content: content
                };

                const existingReports = JSON.parse(localStorage.getItem('rockwoodReports') || '[]');
                existingReports.push(reportData);
                localStorage.setItem('rockwoodReports', JSON.stringify(existingReports));

                alert('✅ 数据已成功保存到后台！\n\n📁 问卷数据：survey_data/\n📄 评估报告：@data/');
            } catch (error) {
                console.error('保存失败:', error);
                alert(rockwoodConfig.messages.saveError + error.message);
            } finally {
                this.isSaving = false;
            }
        },

        async saveToBackend() {
            const surveyData = {
                // 记录人信息
                surveyId: this.recorderInfo.surveyId,
                recorderName: this.recorderInfo.name,
                recorderPosition: this.recorderInfo.position,
                recorderInstitution: this.recorderInfo.institution,
                recorderContact: this.recorderInfo.contact,

                // 被评估人信息
                patientName: this.formData.patientName || "未填写",
                age: this.formData.age || 0,
                gender: this.formData.gender,
                height: this.formData.height,
                weight: this.formData.weight,
                phone: this.formData.phone,
                recordTime: this.formData.recordTime,
                remarks: this.formData.remarks,

                // Rockwood CFS评估结果
                cfsScore: this.result.score,
                functionalAssessment: this.formData.functionalAssessment,
                mobilityLevel: this.formData.mobilityLevel,
                level: this.result.level,
                category: this.result.category,
                description: this.result.description,
                recommendations: this.result.recommendations,

                // 时间戳
                createdAt: new Date().toISOString()
            };

            // 发送到后台API
            const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-rockwood-survey`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(surveyData)
            });

            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }

            // 同时保存到本地存储作为备份
            const existingSurveys = JSON.parse(localStorage.getItem('rockwoodSurveyData') || '[]');
            existingSurveys.push(surveyData);
            localStorage.setItem('rockwoodSurveyData', JSON.stringify(existingSurveys));
        },

        async saveFileToDataFolder(content) {
            // 通过API保存文件到@data/文件夹
            const filename = `Rockwood临床衰弱量表评估结果_${this.recorderInfo.surveyId}_${this.formData.patientName}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.txt`;

            const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-file`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    filename: filename,
                    content: content,
                    surveyId: this.recorderInfo.surveyId
                })
            });

            if (!response.ok) {
                throw new Error('保存评估报告失败');
            }
        },

        resetForm() {
            // 重置表单数据
            this.formData = {
                patientName: '',
                age: null,
                gender: '',
                height: null,
                weight: null,
                phone: '',
                recordTime: '',
                remarks: this.recorderInfo.defaultRemarks || '',
                cfsScore: null,
                functionalAssessment: '',
                mobilityLevel: ''
            };

            // 重新设置当前时间
            const now = new Date();
            const year = now.getFullYear();
            const month = String(now.getMonth() + 1).padStart(2, '0');
            const day = String(now.getDate()).padStart(2, '0');
            const hours = String(now.getHours()).padStart(2, '0');
            const minutes = String(now.getMinutes()).padStart(2, '0');
            this.formData.recordTime = `${year}-${month}-${day}T${hours}:${minutes}`;

            // 重置结果
            this.result = {
                score: 0,
                level: '',
                category: '',
                description: '',
                color: '',
                recommendations: [],
                functionalStatus: '',
                mobilityLevel: ''
            };

            this.showResult = false;
        }
    }
}
</script>

<style scoped>
.rockwood-survey {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px;
    position: relative;
}

.header h1 {
    margin: 0 0 10px 0;
    font-size: 2.2em;
    font-weight: 600;
}

.subtitle {
    margin: 0 0 20px 0;
    opacity: 0.9;
    font-size: 1.1em;
}

.header-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.home-btn,
.settings-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.home-btn:hover,
.settings-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.settings-modal,
.export-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.settings-content,
.export-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.settings-header,
.export-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.recorder-info-display {
    margin-bottom: 30px;
}

.recorder-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.recorder-main-info h3 {
    margin: 0 0 5px 0;
    color: #495057;
}

.recorder-main-info p {
    margin: 5px 0;
    color: #6c757d;
}

.recorder-actions {
    display: flex;
    gap: 10px;
}

.edit-recorder-btn,
.export-btn {
    padding: 8px 16px;
    border: 1px solid #007bff;
    background: white;
    color: #007bff;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.edit-recorder-btn:hover,
.export-btn:hover {
    background: #007bff;
    color: white;
}

.section {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.section h2 {
    margin: 0 0 20px 0;
    color: #333;
    font-size: 1.5em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.assessment-description {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    color: #495057;
    border-left: 4px solid #667eea;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.required {
    color: #dc3545;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.field-hint {
    font-size: 12px;
    color: #6c757d;
    margin-top: 5px;
    margin-bottom: 0;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.radio-group label:hover {
    background-color: #f8f9fa;
}

.cfs-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cfs-option {
    border: 2px solid #e9ecef;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.cfs-option:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.cfs-label {
    display: block;
    cursor: pointer;
    padding: 0;
    margin: 0;
}

.cfs-label input[type="radio"] {
    display: none;
}

.cfs-label input[type="radio"]:checked+.cfs-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.cfs-content {
    padding: 20px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.cfs-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

.cfs-score {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 14px;
}

.cfs-label input[type="radio"]:checked+.cfs-content .cfs-score {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.cfs-level {
    font-weight: 600;
    font-size: 16px;
}

.cfs-description {
    margin: 0;
    line-height: 1.5;
    opacity: 0.9;
}

.question-item {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #f0f0f0;
}

.question-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.question-item h3 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 1.2em;
}

.question-desc {
    margin: 0 0 15px 0;
    color: #666;
    line-height: 1.5;
}

.hint {
    font-size: 12px;
    color: #6c757d;
    margin-top: 5px;
    font-style: italic;
}

.submit-section {
    text-align: center;
    margin-top: 30px;
}

.submit-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.result-section {
    margin-top: 30px;
}

.result-section h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
}

.result-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.result-summary {
    text-align: center;
    padding: 20px;
    border-radius: 10px;
    background: #f8f9fa;
    margin-bottom: 25px;
    border-left: 5px solid #667eea;
}

.result-summary h3 {
    margin: 0 0 10px 0;
    font-size: 1.8em;
    color: #333;
}

.score,
.category {
    margin: 5px 0;
    font-size: 1.1em;
    color: #666;
}

.result-details,
.result-supplements,
.result-recommendations,
.result-explanation {
    margin-bottom: 25px;
}

.result-details h4,
.result-supplements h4,
.result-recommendations h4,
.result-explanation h4 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.2em;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 5px;
}

.level-description {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    line-height: 1.6;
    color: #495057;
    margin: 0;
}

.result-supplements ul,
.result-recommendations ul,
.result-explanation p {
    margin: 0;
    padding-left: 0;
}

.result-supplements li,
.result-recommendations li {
    list-style: none;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.result-supplements li:last-child,
.result-recommendations li:last-child {
    border-bottom: none;
}

.result-explanation p {
    margin: 5px 0;
    color: #666;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.save-btn,
.reset-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
}

.save-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

.save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.reset-btn {
    background: #6c757d;
    color: white;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.reset-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 117, 125, 0.4);
}

.settings-actions,
.export-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
}

.save-settings-btn,
.export-confirm-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-settings-btn:hover,
.export-confirm-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.export-confirm-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.cancel-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cancel-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.export-info {
    background: #e7f3ff;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #007bff;
}

.export-info p {
    margin: 5px 0;
    color: #004085;
}

.export-options {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.export-options .form-group {
    margin-bottom: 10px;
}

.export-options .form-group:last-child {
    margin-bottom: 0;
}

.export-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .rockwood-survey {
        padding: 15px;
    }

    .header h1 {
        font-size: 1.8em;
    }

    .header-actions {
        flex-direction: column;
        align-items: center;
    }

    .recorder-card {
        flex-direction: column;
        text-align: center;
    }

    .settings-content,
    .export-content {
        width: 95%;
        padding: 20px;
    }

    .action-buttons {
        flex-direction: column;
        align-items: center;
    }

    .save-btn,
    .reset-btn {
        width: 200px;
    }
}
</style>